<template>
  <div class="reflect-add">
    <div class="crumbs-link reflect-add-link clear">
      <em @click="goback()">教学反思</em>
      <strong>
        <i>></i>{{name}}</strong>
      <el-button type="primary" class="fr" @click="saveLive()">发表</el-button>
    </div>

    <div class="reflect-add-cont">
      <el-input v-model.trim="title" min="3" max="20" placeholder="请输入标题"></el-input>
      <vue-editor v-model="content" :editorToolbar="customToolbar" placeholder="请输入内容">
      </vue-editor>
    </div>
  </div>
</template>

<script>
import { VueEditor } from "vue2-editor";
export default {
    components: {
        VueEditor
    },
    data() {
        return {
            name: this.$route.query.name,
            id: "",
            schedule_id: "",
            title: "",
            content: "",
            authority: "1",
            customToolbar: [
                [{ list: "ordered" }, { list: "bullet" }],
                [{ color: [] }, { background: [] }],
                ["clean"]
            ]
        };
    },
    created() {
        this.getData();
    },

    methods: {
        getData() {
            let success = data => {
                this.id = data.data.id;
                this.schedule_id = data.data.schedule_id;
                this.title = data.data.title;
                this.content = data.data.content;
            };
            this.$ajax({
                url: "api/teachingschedule/schedule_feedback",
                method: "get",
                params: {
                    id: this.$route.query.id
                },
                func: {
                    success: success
                }
            });
        },
        saveLive() {
            if (this.title == "") {
                this.$message.error("请输入标题哦~");
                return false;
            }
            if (this.content == "") {
                this.$message.error("请输入内容哦~");
                return false;
            }
            var params = {
                id: this.id, //教学反思id
                schedule_id: this.schedule_id, //评课id
                title: this.title,
                content: this.content
            };
            let success = data => {
                this.$message.success(data.msg);
                setTimeout(() => {
                    this.$router.push({ path: "/course2/reflect" });
                }, 1000);
            };

            this.$ajax.put("api/teachingschedule/schedule_feedback", params, {
                func: { success: success }
            });
        },
        goback() {
            this.$router.back(-1);
        }
    }
};
</script>